package com.ambitor.ipro.service;

import java.sql.Connection;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ambitor.grass.sql.dao.BaseDao;
import com.ambitor.grass.sql.dao.SuperDao;
import com.ambitor.grass.sql.dao.impl.BaseDaoImpl;
import com.ambitor.grass.sql.dao.impl.SuperDaoImpl;
import com.ambitor.ipro.util.SkyenccUtil;

public class BaseService {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	protected BaseDao baseDao;

	protected SuperDao superDao;

	private String time = null;

	public BaseService() {
	}

	public BaseService(Connection conn) {
		baseDao = new BaseDaoImpl(conn);
		superDao = new SuperDaoImpl(baseDao);
	}

	public BaseService(BaseDao baseDao) {
		this.baseDao = baseDao;
		superDao = new SuperDaoImpl(baseDao);
	}

	public BaseService(SuperDao superDao) {
		this.superDao = superDao;
		this.baseDao = superDao.getBaseDao();
	}

	public SuperDao getSuperDao() {
		return superDao;
	}

	public void setSuperDao(SuperDao superDao) {
		this.superDao = superDao;
		this.baseDao = superDao.getBaseDao();
	}

	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
		superDao.setBaseDao(baseDao);
	}

	public String getTime() {
		if (time == null) {
			return SkyenccUtil.formatDate(new Date());
		} else {
			return time;
		}
	}

	public String getNewTime() {
		return SkyenccUtil.formatDate(new Date());
	}
}
